import { create } from 'zustand';
import {immer} from 'zustand/middleware/immer';
import { createJSONStorage, persist } from 'zustand/middleware';
const useFactorStore = create(
    immer(
        persist(() => {
            return {
                tableData: [],
                selectFactorData: {}
            }
        },{
            name:'factorStore',
            storage: createJSONStorage(() => sessionStorage),
        })
    )
);

export const  setFactorData = async() => {
    // ajax
    const data = await Promise.resolve([{id: 1, name: '张三'}, {id: 2, name: '李四'}]);
    useFactorStore.setState({tableData: data});
}

export const setSelectFactorData = async(data) => {
    // ajax
    const info = await Promise.resolve({id:100,name:'因子信息'});
    useFactorStore.setState({selectFactorData: info});
}


export default useFactorStore;